﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace GameName1
{
    class GameOverScene : GameScene
    {
        private Texture2D _backgroundSprite;
        private Texture2D _playAgainSprite;
        private Texture2D _gameOverSprite;
        private Texture2D _barSprite;

        private SpriteFont _font;

        private int _points;

        private MouseState _mouseState;

        private Rectangle _playAgainBounds;

        public GameOverScene(int points)
        {
            LoadContent();
            _points = points;        
        }

        public override void LoadContent()
        {
            base.LoadContent();

            _backgroundSprite = ContentManager.Load<Texture2D>("Sprites/background");
            _barSprite = ContentManager.Load<Texture2D>("sprites/bar");

            _playAgainSprite = ContentManager.Load<Texture2D>("Sprites/playagain");
            _gameOverSprite = ContentManager.Load<Texture2D>("Sprites/gameover");

            _font = ContentManager.Load<SpriteFont>("myFont");

            _playAgainBounds = new Rectangle((int) ((ScreenManager.GetInstance().Resolution.X / 2) - (_playAgainSprite.Width / 2)),
                (int) (ScreenManager.GetInstance().Resolution.Y / 4 * 3) - (_playAgainSprite.Height / 2),
                _playAgainSprite.Width,
                _playAgainSprite.Height);
        }
        public override void UnloadContent()
        {
            base.UnloadContent();
            ContentManager.Unload();
        }

        public override void Update(GameTime gameTime)
        {
            _mouseState = Mouse.GetState();

            if (_playAgainBounds.Contains(new Point(_mouseState.X, _mouseState.Y)) && _mouseState.LeftButton == ButtonState.Pressed)
                ScreenManager.GetInstance().CurrentScreen = new GameplayScene();
        }
        public override void Draw(SpriteBatch spriteBatch)
        {
            DrawBackground(spriteBatch);
            DisplayScore(spriteBatch);
            DisplayShields(spriteBatch);
            
            spriteBatch.Draw(_gameOverSprite,
                new Vector2((ScreenManager.GetInstance().Resolution.X/2) -_gameOverSprite.Width/2,
                    ScreenManager.GetInstance().Resolution.Y/2-_gameOverSprite.Height/2),Color.White);
            

            spriteBatch.Draw(_playAgainSprite, _playAgainBounds, Color.White);

            if (_playAgainBounds.Contains(new Point(_mouseState.X, _mouseState.Y)))
                spriteBatch.Draw(_playAgainSprite, _playAgainBounds, new Color(0,255,0));
        }
        
        private void DrawBackground(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(_backgroundSprite, new Vector2(0, 0), Color.White);
            spriteBatch.Draw(_barSprite, new Vector2(20, ScreenManager.GetInstance().Resolution.Y - 15));
        }
        private void DisplayScore(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(_font, "SCORE:", new Vector2(5, 5), Color.White);
            spriteBatch.DrawString(_font, _points.ToString(), new Vector2(85, 5), new Color(0, 255, 0));
        }
        private void DisplayShields(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(_font, "LIVES:", new Vector2(575, 5), Color.White);
        }
    }
}
